import store from '../index.js';
import http from '@/common/http.js'
import $api from 'api'

const state = {
	userInfo: uni.getStorageSync('userInfo') || ''
}

const mutations = {
	// 更新用户信息
	UPDATE_USERINFO: function(state, payLoad) {

		console.log('UPDATE_USERINFO', payLoad)
		state.userInfo = payLoad.data
		// state.userInfo.nickName = 'nekomata'
		console.log(state)
		console.log(payLoad)
		uni.setStorageSync('userInfo', payLoad.data);
	}
}

const actions = {
	// 获取用户信息
	async setUserInfo(context, userInfo) {
		console.log(context)
		// let userInfo = await $api.getUserInfo()
		context.commit('UPDATE_USERINFO', {...context.userInfo, ...userInfo})
	}
}

export default {
	state,
	mutations,
	actions
}
